package com.syb.controller.user;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.syb.entity.user.SysUser;
import com.syb.service.UserService;
import com.syb.util.PageResults;

@Namespace("/user")
public class UserController extends ActionSupport{

	Logger logger = Logger.getLogger(UserController.class);
	
	@Autowired
	private UserService userService;
	
	private Integer currentPage;
	
	@Action(value="getUserList",
			results={
			@Result(name="success",location="/jsp/background/user/list.jsp"),
			@Result(name="error",location="/error.jsp")
			})
	public String getUserList(){
		PageResults<SysUser> page = new PageResults<SysUser>();
		PageResults<SysUser> sysUserList = new PageResults<SysUser>();
		//组装参数
		if(currentPage!=null&&!currentPage.equals("")){
			page.setCurrentPage(currentPage);
		}
		try{
			sysUserList = userService.getUserList(page);
		}catch(Exception e){
			logger.error(e.getMessage());
			ActionContext.getContext().put("error","查询出错！");
			return "error";
		}
		ActionContext.getContext().put("result", sysUserList);
		return "success";
	}
	

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}
	
	
}
